<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>javascript</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box
    }
    body {
      font-size: 14px;
      padding: 20px;
    }
    ul li {
      line-height: 30px;
    }
  </style>
</head>
<body>
  <ul>
    <li></li>
  </ul>
</body>
<script src="https://cdn.bootcss.com/vue/2.6.8/vue.js"></script>
<script>
    // 观察者
    function Observer() {
        this.update = function(...args) {
            console.log(...args)
        }
    }
    // 观察者列表
    function ObserverList() {
        this.observerList = []
    }
    // 新增观察者
    ObserverList.prototype.add = function(obj) {
        this.observerList.push(obj)
    }

    // 发布者目标
    function Subject() {
        this.observers = new ObserverList()
    }
    Subject.prototype.subscribe = function(obj) {
        this.observers.add(obj)
    }
    Subject.prototype.notify = function(...args) {
        var l = this.observers.observerList.length
        console.log(l)
        for(var i = 0; i < l; i++) {
            this.observers.observerList[i].update(...args)
        }
    }
    var obs = new Observer()
    var sub = new Subject()
    console.log(sub)
    sub.subscribe(obs)
    sub.subscribe(obs)
    sub.subscribe(obs)
    sub.notify(123,234)




</script>
</html>